package com.education.webservlet;

import com.education.db.HibernateSessionFactory;
import com.education.db.dao.InfoUserDAO;
import com.education.db.domain.InfoUser;
import com.education.service.bean.UserBean;
import com.education.util.Constant;
import com.education.util.MD5Util;
import org.hibernate.Transaction;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Fan307 on 2016/11/7.
 */
@WebServlet(name = "LogoutServlet")
public class LogoutServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    public LogoutServlet() {

        super();
    }

    public void destroy() {
        super.destroy();
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding(Constant.CHAR_ENCODING);

        UserBean userBean = (UserBean)request.getSession().getAttribute("userBean");
        if(userBean != null){
            request.getSession().removeAttribute("userBean");
        }
        String info = String.format("退出成功，2秒后为您自动跳到首页！！<meta http-equiv='refresh' content='2;url=%s'", request.getContextPath()+"/initActivity");
        request.setAttribute("info", info);
        request.getRequestDispatcher("/Pages/message.jsp").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    public void init() throws ServletException {

    }
}
